// This fixes it so you can save cameras

local function Save(Entity, Copy, Save)
	if (Copy.Class == "gmod_cameraprop") then
		local Key = Entity:GetNetworkedInt(0)
		
		Save.key = Key
	end
end

ContraptionSaver.Hooks.Add("Save Entity", Save)

// Register entity class

local function Register(Player, Pos, Ang, Key, Locked, Toggle, Vel, aVel, Frozen, Nocollide)
	local Camera = ents.Create("gmod_cameraprop")
	
	Camera:SetAngles(Ang)
	Camera:SetPos(Pos)
	Camera:Spawn()
	
	Camera:GetTable():SetKey(Key)
	Camera:GetTable():SetPlayer(Player)
	Camera:GetTable():SetLocked(Locked)
	Camera:GetTable().toggle = Toggle
	Camera:GetTable():SetTracking(NULL, Vector(0))
	
	// Toggle or no toggle
	
	if (Toggle == 1) then
		numpad.OnDown(Player, Key, "Camera_Toggle", Camera)
	else
		numpad.OnDown(Player, Key, "Camera_On", Camera)
		numpad.OnUp(Player, Key, "Camera_Off", Camera)
	end
	
	// Check nocollide
	
	if (Nocollide) then Camera:GetPhysicsObject():EnableCollisions(false) end
	
	// Merge table
	
	local Table = 
	{
		key		    = Key,
		toggle 		= Toggle,
		locked      = Locked,
		pl			= Player,
		nocollide 	= nocollide
	}
	
	table.Merge(Camera:GetTable(), Table)
	
	// Get player's UniqueID
	
	local ID = Player:UniqueID()
	
	// List of cameras
	
	GAMEMODE.CameraList[ID] = GAMEMODE.CameraList[ID] or {}
	
	// Players camera list
	
	local List = GAMEMODE.CameraList[ID]
	
	if (List[Key] and List[Key] != NULL ) then
		local Entity = List[Key]
		
		Entity:Remove()
	end
	
	// Add new camera
	
	List[Key] = Camera
	
	return Camera
end

duplicator.RegisterEntityClass("gmod_cameraprop", Register, "Pos", "Ang", "key", "locked", "toggle", "Vel", "aVel", "frozen", "nocollide")